<!-- 策划案例库 -->
<!-- from src\views\design\projectDesignManage\index.vue （设计策划书管理）-->
<template>
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card :bordered="false" style="over-flow:scroll">
      <div>
        <a-row>
          <a-col :md="24" :sm="19">
            <list-table
              ref="table"
              class="export-table"
              :columns="columns"
              :start-index="0"
              :request="loadData"
              row-key="designId"
              :statistics-config="{ use: true, total, temp }"
              :export-config="{
                use: true,
                select: $route.meta.title,
                all: $route.meta.title
              }"
              :exportPermission="{ select: 'ds_042_exp_04', all: 'ds_042_exp_04' }"
            >
              <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
              <span slot="actions" slot-scope="text, record">
                <MoreButton>
                  <a @click="handleLook(record)" v-btnPermission="'ds_042_loo_01'">查看</a>
                  <a @click="handleDel(record)" v-btnPermission="'ds_042_del_02'">删除</a>
                  <BasePrintButton class="_print" v-btnPermission="'ds_042_pri_03'" buttonType="a" :showDivider="false" :beforePrintFn="() => beforePrintFn(record.id)" />
                </MoreButton>
              </span>
            </list-table>
          </a-col>
        </a-row>
      </div>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { print } from '@/api/design/demand'
import { knowledgePlanList, knowledgePlanDel } from '@/api/design/knowledgeBase/plan'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import moment from 'moment'

const columns = [
  {
    title: '序号',
    width: '65px',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '分公司',
    width: '120px',
    dataIndex: 'branchCompanyName'
  },
  {
    title: '项目名称',
    width: '200px',
    dataIndex: 'projectName'
  },
  {
    title: '项目业态',
    width: '200px',
    dataIndex: 'projectFormats'
  },
  {
    title: '项目设计管理类别',
    width: '150px',
    dataIndex: 'designType'
  },
  {
    title: '创建人',
    width: '100px',
    dataIndex: 'createName'
  },
  {
    title: '创建时间',
    width: '200px',
    dataIndex: 'createDate'
  },
  {
    title: '是否一次性审批通过',
    width: '100px',
    dataIndex: '_firstPass'
  },
  {
    title: '评审分数',
    width: '100px',
    dataIndex: 'auditScore'
  },
  {
    title: '操作',
    dataIndex: 'actions',
    width: '150px',
    fixed: 'right',
    scopedSlots: { customRender: 'actions' }
  }
]
export default {
  name: 'knowledgeBasePlan',
  components: {},
  data() {
    this.columns = columns
    return {
      beforePrintFn: async id => {
        let res = await print({ id })
        return res.data.content
      },
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        // 格式化参数
        if (this.queryParam._dateRange && this.queryParam._dateRange.length > 0) {
          this.queryParam.startDate = moment(this.queryParam._dateRange[0]).format("YYYY-MM-DD") + ' 00:00:00'
          this.queryParam.endDate = moment(this.queryParam._dateRange[1]).format('YYYY-MM-DD') + ' 23:59:59'
        }

        let requestParameters = {
          ...parameter,
         ...this.queryParam
        }
        return knowledgePlanList(requestParameters).then(res => {
          res.data.forEach(item => {
            item._firstPass = [null, undefined].includes(item.firstPass) ? item.firstPass : item.firstPass ? '是' : '否'
          })
          return res
        })
      },
      total: {},

      // 搜索条件
      searchArr: [
        // {
        //   name: '设计策划书名称',
        //   value: 'designName',
        //   type: 'input'
        // },
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect
        },
        {
          name: '设计管理类别',
          value: 'designType',
          type: 'select',
          data: [
            {
              value: 'A1类',
              label: 'A1类'
            },
            {
              value: 'A2类',
              label: 'A2类'
            },
            {
              value: 'A3类',
              label: 'A3类'
            },
            {
              value: 'B类',
              label: 'B类'
            },
            {
              value: 'C类',
              label: 'C类'
            }
          ]
        },
        {
          name: '创建时间',
          value: '_dateRange',
          type: 'dateRange'
        },
        {
          name: '是否一次性审批通过',
          type: 'select',
          value: 'firstPass',
          data: [
            {
              value: true,
              label: '是'
            },
            {
              value: false,
              label: '否'
            }
          ]
        }
      ],

      temp: () => {
        return <div></div>
      }
    }
  },
  computed: {},
  created() {},
  methods: {
    search(values) {
      this.queryParam = values
      this.$refs.table.refresh(true)
    },
    // 点击【查看】
    handleLook(record) {
      this.$router.push({
        // 跳转【设计策划书管理】详情页
        path: '/project/design/viewDesignManage',
        query: {
          //  后台将详情需要的 id 放到 oldDesignId 字段上
          id: record.oldDesignId,
          type: 'view',
          status: 2
        }
      })
    },
    // 表单行 - 删除
    handleDel(record) {
      this.$confirm({
        title: '温馨提示',
        content: `请确认是否要删除数据？`,
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk: () => {
          knowledgePlanDel({ designId: record.designId }).then(res => {
            if (res.data.code === 200) {
              this.$message.success('删除成功')
              this.$refs.table.getData(null, true)
            } else {
              this.$message.warning(res.data.message)
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
._print {
  /deep/a {
    padding: 0 !important;
  }
}
</style>
